<?php
        $link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db('livechat') or die('Could not select database.');
$query = "SELECT m.text, c.ChatName, u.FirstName, u.LastName FROM user u, messages m, chat c WHERE m.Chat_idChat = c.idChat AND m.User_idUser = u.idUser";
$result = mysql_query($query);

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}


if (mysql_num_rows($result) == 0) {
    echo "Welcome a customer service rep will be with you shortly";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
while ($row = mysql_fetch_assoc($result)) {
    echo '<span style="font-size:large">'. $row["FirstName"].' '.$row["LastName"]. "</span>";
    echo ' - '. $row["text"]. "<br />";
}

mysql_free_result($result);

mysql_close($link);?>